package com.cloud.redis7.demo;

import redis.clients.jedis.Jedis;

import java.util.*;

public class JedisDemo {
    private  static String ip="192.168.18.128";
    private  static Integer port=6379;
    private  static String auth="123456";
    public static void main(String[] args) {

        Jedis jedis = new Jedis(ip,port);
        jedis.auth(auth);
        System.out.println(jedis.ping());
        //keys
        Set<String> keys = jedis.keys("*");
        System.out.println(keys);
        //String
        jedis.set("k5", "欢子");
        System.out.println(jedis.get("k5"));
        System.out.println(jedis.ttl("k5"));
        jedis.expire("k5",20l);


        //list
        jedis.lpush("list","23","24","25","26");
        List<String> list = jedis.lrange("list", 0, -1);
        for (String element : list) {
            System.out.println(element);
        }

        //set
        jedis.sadd("orders","jd001");
        jedis.sadd("orders","jd002");
        jedis.sadd("orders","jd003");
        Set<String> set1 = jedis.smembers("orders");
        for (Iterator iterator = set1.iterator(); iterator.hasNext();) {
            String string = (String) iterator.next();
            System.out.println(string);
        }
        jedis.srem("orders","jd002");
        System.out.println(jedis.smembers("orders").size());
        //hash
        jedis.hset("hash1","userName","lisi");
        System.out.println(jedis.hget("hash1","userName"));
        Map<String,String> map = new HashMap<String,String>();
        map.put("telphone","138xxxxxxxx");
        map.put("address","水城公寓");
        map.put("email","2288@126.com");
        jedis.hmset("hash2",map);
        List<String> result = jedis.hmget("hash2", "telphone","email");
        for (String element : result) {
            System.out.println(element);
        }

        //zset
        jedis.zadd("zset01",60d,"v1");
        jedis.zadd("zset01",70d,"v2");
        jedis.zadd("zset01",80d,"v3");
        jedis.zadd("zset01",90d,"v4");

        List<String> zset01 = jedis.zrange("zset01", 0, -1);
        zset01.forEach(System.out::println);
    }

}
